#!/usr/bin/perl -wc

package RFCMail::ESMTP::Server::State;

use strict;
use warnings;


sub new {
    my $class = shift;
    return (bless {@_}, $class);
}


sub reset {
    my ($self) = @_;
    delete @{$self}{grep(/^[a-z]/, keys %{$self})};
    return ($self);
}


sub recipients {
    my ($self) = @_;
    return ()
	if not defined($self->{recipients});
    return (@{$self->{recipients}});
}


sub state {
    my ($self) = @_;
    return (0) # <= greeting not yet received
	if not defined($self->{Greeting});
    return (1) # <= no mail transaction in progress; awaiting "MAIL FROM:"
	if not defined($self->{sender});
    return (2) # <= "MAIL FROM:" received, but no valid recipients yet
	if not $self->recipients;
    return (3);# <= valid recipients exist; "DATA" acceptable
}


1;
